import React from 'react';
// 引入函数中操作redux 的hook;
import { useSelector, useDispatch } from 'react-redux'
// 导入use模块的任务
import { addAgeAction } from '../../store3/actions/userAction'
// 导入商品模块的任务
import { getSchoollistAsync } from '../../store3/actions/shopAction'
import { useEffect } from 'react'
const Father = () => {
    // 获取仓库中的数据
    const shop = useSelector(state => state.shop);
    const user = useSelector(state => state.user)
    //console.log('store', store);
    const dispatch = useDispatch();

    console.log('shop', shop)
    useEffect(() => {
        dispatch(getSchoollistAsync())
    }, [])

    return (
        <div>
            {/* 使用user模块 */}
            <p>user:{user.userinfo.name}-{user.userinfo.age}</p>
            <p><button onClick={() => {
                dispatch(addAgeAction(10))
            }}>修改年龄</button></p>

            {/* 商品模块 */}
            <ul>
                {
                    shop.schoollist.map(item => {
                        return <li key={item.id}>{item.school_name}</li>
                    })
                }
            </ul>
        </div>
    );
}

export default Father;
